<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>SysCompensation</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../layui-v2.6.8/layui/css/layui.css"  media="all">
    <script type="text/javascript" src="../../layui-v2.6.8/layui/layui.js"></script>
    <script type="text/javascript" src="../../js/jQuery%20v3.6.0.js"></script>
</head>
<body>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>赔偿申请清单</legend>
</fieldset>


<form class="layui-form" action="">
    <div class="layui-form-item f1">
        <div class="layui-inline">
            <div class="layui-inline">
                <label class="layui-form-label" style="font-size: 16px">订单编号：</label>
                <div class="layui-input-block">
                    <input type="text" id="com_oid" name="title" class="layui-input" style="width: 200px">
                </div>
            </div>
            <button type="button" id="find" class="layui-btn layui-btn-normal">查询</button>
        </div>
        <table class="layui-hide" id="compen" lay-filter="operation">

            <script type="text/html" id="barDemo">
                <a class="layui-btn layui-btn-xs" lay-event="comps" id="comp">确认赔偿</a>
            </script>

        </table>

    </div>

</form>

<script>
    var table = layui.table;
    var layer = layui.layer;

    layui.use('table', function(){
        table.render({
            elem: '#compen'
            ,url:'http://localhost:8080/searchallcom'
            ,toolbar: '#toolbarDemo'
            ,defaultToolbar: ['filter', 'exports', 'print']
            ,page: true
            ,cols: [[
                {field:'comid',title: '赔偿单号', sort: true}
                ,{field:'com_oid',title: '订单编号', sort: true}
                ,{field:'cause',title: '赔偿原因'}
                ,{field:'com_pay',title: '赔偿金额'}
                ,{field:'com_date',title: '赔偿时间', sort: true}
                // ,{field:'com_eid',title: '负责人',}
                ,{field:'comp',title: '确认赔偿', toolbar: '#barDemo'}
            ]]
        });
    });

    //查询
    $("#find").click(function () {
        var oid=$('#com_oid').val()
        //开始查询逻辑
        //id空
        if(oid==null||oid==undefined||oid=="") {
            location.reload();
        }else{
            //时间空，按id查
            layer.open({
                area: ['100%', '400px'], //宽高
                title: ["查询结果", "align:center"],
                maxmin: false,
                content: '<div><table id="c" lay-filter="operation"></table></div>',
                success: function () {
                    table.render({
                        elem: '#c',
                        url: 'http://localhost:8080/searchComById?oid=' + oid,
                        page: true
                        , cols: [[
                            {field:'comid',title: '赔偿单号', sort: true}
                            ,{field:'com_oid',title: '订单编号', sort: true}
                            ,{field:'cause',title: '赔偿原因'}
                            ,{field:'com_pay',title: '赔偿金额'}
                            ,{field:'com_date',title: '赔偿时间', sort: true}
                            // ,{field:'com_eid',title: '负责人',}
                            ,{field:'comp',title: '确认赔偿', toolbar: '#barDemo'}
                        ]]
                    });
                }
            });
        }
    })


    //确认收货事件
    table.on('tool(operation)',function (obj){
        var data = obj.data;

        if(obj.event === 'comps'){
            if(data.com_date!=null){
                alert('已赔偿');
            }else {
                layer.confirm("你确认通过 "+data.comid+" 的赔偿申请吗？",function () {
                    $.ajax({
                        url:'http://localhost:8080/comConfirm?comid='+data.comid+'&eid'+1,
                        async: true,
                        type : 'get',
                        dataType: 'json',
                        success: function (data) {
                            if (data.code === 0) {
                                layer.msg("确认成功");
                                setTimeout('location.reload()','1000');
                                ;
                            } else {
                                layer.msg("确认失败");
                            }
                        }
                        ,false: function () {
                            layer.msg("Error!");
                        }
                    })
                })
            }
        }

    })

</script>


</body>
</html>